<template>
    <div>
        <template>
            <div class="align-right">
              <el-form :inline="true" :model="listQuery">
                  <div class="pull-right">
                    <el-form-item label="状态：">
                            <el-select v-model="listQuery.status" placeholder="请选择状态">
                                <el-option
                                v-for="item in options"
                                :key="item.codeKey"
                                :label="item.codeValue"
                                :value="item.codeKey">
                                </el-option>
                            </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-date-picker 
                            v-model="listQuery.rangeDate" 
                            value-format="yyyy-MM-dd hh:mm:ss" 
                            type="daterange" 
                            align="right" 
                            unlink-panels 
                            range-separator="至" 
                            start-placeholder="开始日期" 
                            end-placeholder="结束日期" 
                            :picker-options="pickerOptions">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                    <el-input
                        placeholder="请输入关键词或ID"
                        clearable
                        v-model="listQuery.keyword">
                    </el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" @click="handleSearch" icon="el-icon-search" >搜索</el-button>
                    </el-form-item>
                  </div>
                  <div>
                    <el-button  @click="addGraphicContent">发布内容</el-button>
                  </div>
              </el-form>
            </div>
            <el-table
                class="mb20"
                ref="graphic_table"
                :data="graphic_tables"
                row-key="id"
                border
                highlight-current-row
                @selection-change="handleSelectionChange"
                style="width: 100%">
                <el-table-column
                    type="selection"
                    width="55">
                </el-table-column>
               <el-table-column align="center" label="序号" min-width ="70" >
                    <template slot-scope="scope">
                        <span>{{ scope.$index+1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="标题" min-width ="450" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.title }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="置顶" min-width ="80" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.isToTop }}</span>
                    </template>
                </el-table-column>
                 <el-table-column align="center" label="发布者" min-width ="80" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.createNm }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="发布时间" min-width ="155" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.publishDt }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="状态" min-width ="80" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.stateNm }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="喜欢" min-width ="80" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.likeNum }}</span>
                    </template>
                </el-table-column>

                <el-table-column align="center" label="操作" width ="270" >
                    <template slot-scope="scope">
                        <el-button type="text"  @click="edit(scope)">编辑</el-button>
                        <span>|</span>
                        <el-button type="text"  @click="remove(scope)">删除</el-button>
                        <span>|</span>
                        <el-button type="text" @click="push(scope)">推送</el-button>
                        <span>|</span>
                        <el-button type="text" @click="revoke(scope)">撤稿</el-button>
                        <span>|</span>
                        <el-button type="text" @click="comment(scope)">评论</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-col :span="24" style="margin-top:10px" v-if="graphic_tables.length>0">
                <el-button size="small" @click="bathRemove">批量删除</el-button>
                <el-button size="small" @click="bathRevoke">批量撤稿</el-button>
                 <el-button size="small" @click="bathTop">保存置顶</el-button>
            </el-col>
             <el-col :span="24" class="pagination-warp" v-if="graphic_tables.length>0">
                <div class="text-center">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="listQuery.currentPage"
                        :page-sizes="[10, 20, 30, 50]"
                        :page-size="listQuery.size"
                        layout="total, sizes, prev, pager, next ,jumper"
                        :total="total">
                    </el-pagination>
                </div>
            </el-col>
        </template>
    </div>
</template>
<script>
import {　selectList } from '@/api/content/graphic'
import { getDetail } from '@/api/sys/detail'
export default {
    data() {
        return {
            graphic_tables:[],
            total: null,
            options: [],
            listQuery: {
                currentPage: 1,
                size: 10,
                status: undefined,
                rangeDate:[]
            },
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                    const end = new Date()
                    const start = new Date()
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
                    picker.$emit('pick', [start, end])
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                    const end = new Date()
                    const start = new Date()
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
                    picker.$emit('pick', [start, end])
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                    const end = new Date()
                    const start = new Date()
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
                    picker.$emit('pick', [start, end])
                    }
                }]
            }
        }
    },
    created() {
        this.getList()
        this.getOptions()
    },
    methods:{
        getList(){
            const params = this.listQuery
            selectList(params).then(response => {
                if(response.code === 0){
                    this.graphic_tables  = response.data.records
                    this.total = response.data.total
                }
            })
        },
        getOptions(){
            const param = {masterKey:"CONT_STAT"}
            getDetail(param).then(response => {
                if(response.code === 0){
                    this.options = response.data
                    this.options.unshift({id:-1,codeKey:'',codeValue:'全部'})
                }
            })
        },
        handleSearch(){
            this.listQuery.currentPage = 1
            this.getList()
        },
        handleSizeChange(val) {
            this.listQuery.currentPage = 1
            this.listQuery.size = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.listQuery.currentPage = val
            this.getList()
        },
        handleSelectionChange(val){
            
        },
        addGraphicContent(){
            this.$router.push({"path":"/content/addGraphic","query":{router:'新增图文'}})
        }
       
     }
} 
</script>
<style rel="stylesheet/scss" lang="scss">

.table-search{
  margin: 10px 0px;
}
.bath-operation{
    margin: 10px 0px;
}
.table-page{
    width: 700px;
    margin: 2px auto;
}
</style>